package com.github.shiqiyue.learn.guava;

import com.google.common.primitives.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/***
 * Bytes测试
 * @author wenyao.wu
 * @date 2018/7/3
 */
public class BytesTest {

    private static final Logger logger = LoggerFactory.getLogger(BytesTest.class);

    public static void main(String[] args) {
        byte[] byteArray = {1, 2, 3, 4, 5, 5, 7, 9, 9};

        //convert array of primitives to array of objects
        List<Byte> objectArray = Bytes.asList(byteArray);
        logger.info("{}", objectArray);

        //convert array of objects to array of primitives
        byteArray = Bytes.toArray(objectArray);
        logger.info("{}", byteArray);
        byte data = 5;
        //check if element is present in the list of primitives or not
        logger.info("5 is in list? {}", Bytes.contains(byteArray, data));

        //Returns the index
        logger.info("Index of 5: {}", Bytes.indexOf(byteArray, data));

        //Returns the last index maximum
        logger.info("Last index of 5: {}", Bytes.lastIndexOf(byteArray, data));
    }
}
